<ion-header>
    <ion-navbar core-back-button>
        <ion-title><core-format-text [text]="title" contextLevel="module" [contextInstanceId]="module.id" [courseId]="courseId"></core-format-text></ion-title>
    </ion-navbar>
</ion-header>
<ion-content>
    <ion-refresher [enabled]="entryLoaded && (isPullingToRefresh || !renderingEntry && !loadingRating && !loadingComments)" (ionRefresh)="refreshDatabase($event)">
        <ion-refresher-content pullingText="{{ 'core.pulltorefresh' | translate }}"></ion-refresher-content>
    </ion-refresher>
    <core-loading [hideUntil]="entryLoaded && (isPullingToRefresh || !renderingEntry && !loadingRating && !loadingComments)">
        <!-- Database entries found to be synchronized -->
        <div class="core-warning-card" icon-start *ngIf="entry && entry.hasOffline">
            <ion-icon name="warning"></ion-icon>
            {{ 'core.hasdatatosync' | translate: {$a: moduleName} }}
        </div>

        <ion-item text-wrap *ngIf="groupInfo && (groupInfo.separateGroups || groupInfo.visibleGroups)">
            <ion-label id="addon-data-groupslabel" *ngIf="groupInfo.separateGroups">{{ 'core.groupsseparate' | translate }}</ion-label>
            <ion-label id="addon-data-groupslabel" *ngIf="groupInfo.visibleGroups">{{ 'core.groupsvisible' | translate }}</ion-label>
            <ion-select [(ngModel)]="selectedGroup" (ionChange)="setGroup(selectedGroup)" aria-labelledby="addon-data-groupslabel" interface="action-sheet">
                <ion-option *ngFor="let groupOpt of groupInfo.groups" [value]="groupOpt.id">{{groupOpt.name}}</ion-option>
            </ion-select>
        </ion-item>

        <div class="addon-data-contents addon-data-entries-{{data.id}}" *ngIf="entry">
            <core-style [css]="data.csstemplate" prefix=".addon-data-entries-{{data.id}}"></core-style>

            <core-compile-html [text]="entryHtml" [jsData]="jsData" [extraImports]="extraImports" (compiling)="setRenderingEntry($event)"></core-compile-html>
        </div>

        <core-rating-rate *ngIf="data && entry && ratingInfo && (!data.approval || entry.approved)" [ratingInfo]="ratingInfo" contextLevel="module" [instanceId]="data.coursemodule" [itemId]="entry.id" [itemSetId]="0" [courseId]="courseId" [aggregateMethod]="data.assessed" [scaleId]="data.scale" [userId]="entry.userid" (onLoading)="setLoadingRating($event)" (onUpdate)="ratingUpdated()"></core-rating-rate>
        <core-rating-aggregate *ngIf="data && entry && ratingInfo" [ratingInfo]="ratingInfo" contextLevel="module" [instanceId]="data.coursemodule" [itemId]="entry.id" [courseId]="courseId" [aggregateMethod]="data.assessed" [scaleId]="data.scale"></core-rating-aggregate>

        <ion-item *ngIf="data && data.comments && entry && entry.id > 0 && commentsEnabled">
            <core-comments contextLevel="module" [instanceId]="data.coursemodule" component="mod_data" [itemId]="entry.id" area="database_entry" [displaySpinner]="false" [courseId]="courseId" (onLoading)="setLoadingComments($event)"></core-comments>
        </ion-item>

        <ion-grid *ngIf="previousOffset != null || nextOffset != null">
            <ion-row align-items-center>
                <ion-col *ngIf="previousOffset != null">
                    <button ion-button block outline icon-start (click)="gotoEntry(previousOffset)">
                        <ion-icon name="arrow-back" md="ios-arrow-back"></ion-icon>
                        {{ 'core.previous' | translate }}
                    </button>
                </ion-col>
                <ion-col *ngIf="nextOffset != null">
                    <button ion-button block icon-end (click)="gotoEntry(nextOffset)">
                        {{ 'core.next' | translate }}
                        <ion-icon name="arrow-forward" md="ios-arrow-forward"></ion-icon>
                    </button>
                </ion-col>
            </ion-row>
        </ion-grid>
    </core-loading>
</ion-content>
